//
//  LSZDetailsBranchActivitiesVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/31.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZDetailsBranchActivitiesVC.h"

@interface LSZDetailsBranchActivitiesVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewDetailsBranchActivities;
@end

@implementation LSZDetailsBranchActivitiesVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详情";
    [self.tableViewDetailsBranchActivities registerClass:[LSZOneImageViewTableViewCell class] forCellReuseIdentifier:@"LSZOneImageViewTableViewCell"];
    [self.tableViewDetailsBranchActivities registerClass:[LSZOneLabelTableViewCell class] forCellReuseIdentifier:@"LSZOneLabelTableViewCell"];
    
    if ([NSStr([_MyCenter roleId]) isEqualToString:@"5"]) {

        UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
        but.frame =CGRectMake(0,0, 60, 44);
        [but setTitle:@"删除"forState:UIControlStateNormal];
        [but addTarget:self action:@selector(clickDelete) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem  *barBut = [[UIBarButtonItem alloc]initWithCustomView:but];
        self.navigationItem.rightBarButtonItem = barBut;
    }
 
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        if(self.branchActivitiesMg.subject.length == 0){
            return 0.0001;
        }else{
            NSString * string = [NSString stringWithFormat:@"[%@]:%@",self.branchActivitiesMg.catalogName,self.branchActivitiesMg.subject];
            return [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:40 font:15 :string];
        }
    }else if (indexPath.row == 1){
        if(self.branchActivitiesMg.publishTime.length == 0){
            return 0.0001;
        }else{
            NSString * string = [NSString stringWithFormat:@"活动时间:%@",self.branchActivitiesMg.publishTime];
            return [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:40 font:15 :string];
        }
    }else if (indexPath.row == 2){
        if(self.branchActivitiesMg.address.length == 0){
            return 0.0001;
        }else{
            NSString * string = [NSString stringWithFormat:@"活动地点:%@",self.branchActivitiesMg.address];
            return [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:40 font:15 :string];
        }
    }else if (indexPath.row == 3){
        if(self.branchActivitiesMg.personNames.length == 0){
            return 0.0001;
        }else{
            NSString * string = [NSString stringWithFormat:@"全体人员:%@",self.branchActivitiesMg.personNames];
            return [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:40 font:15 :string];
        }
    }else if (indexPath.row == 4){
        if(self.branchActivitiesMg.content.length == 0){
            return 0.0001;
        }else{
            NSString * string = [NSString stringWithFormat:@"内容:%@",self.branchActivitiesMg.content];
            return [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:ScreenHeight*6 font:15 :string];
            return 80;
        }
    }else if (indexPath.row == 5){
        if(self.branchActivitiesMg.coverUrl.length == 0){
            return 0.0001;
        }else{
            return 100;
        }
    }else{
        return 0.001;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 5) {
        LSZOneImageViewTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZOneImageViewTableViewCell" forIndexPath:indexPath];
        if(self.branchActivitiesMg.coverUrl.length != 0){
            [cell.imageViewOver sd_setImageWithURL:[NSURL URLWithString:self.branchActivitiesMg.coverUrl] placeholderImage:[UIImage imageNamed:@"默认"]];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        return [self NewtableView:tableView cellForRowAtIndexPath:indexPath];
    }
}
-(UITableViewCell *)NewtableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZOneLabelTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZOneLabelTableViewCell" forIndexPath:indexPath];
    cell.labelTiele.numberOfLines = 0;
    NSString * string = [[NSString alloc]init];
    if (indexPath.row == 0) {
        if(self.branchActivitiesMg.subject.length != 0){
            string = [NSString stringWithFormat:@"[%@]:%@",self.branchActivitiesMg.catalogName,self.branchActivitiesMg.subject];
            cell.labelTiele.text = string;
        }
    }else if (indexPath.row == 1){
        if(self.branchActivitiesMg.publishTime.length != 0){
            string = [NSString stringWithFormat:@"活动时间:%@",self.branchActivitiesMg.publishTime];
            cell.labelTiele.text = string;
        }
    }else if (indexPath.row == 2){
        if(self.branchActivitiesMg.address.length != 0){
            string = [NSString stringWithFormat:@"活动地点:%@",self.branchActivitiesMg.address];
            cell.labelTiele.text = string;
        }
    }else if (indexPath.row == 3){
        if(self.branchActivitiesMg.personNames.length != 0){
            string = [NSString stringWithFormat:@"全体人员:%@",self.branchActivitiesMg.personNames];
            cell.labelTiele.text = string;
            
        }
    }else if (indexPath.row == 4){
        if(self.branchActivitiesMg.content.length != 0){
            string = [NSString stringWithFormat:@"内容:%@",self.branchActivitiesMg.content];
            cell.labelTiele.text = string;
            
        }
    }else{
        
    }
    CGFloat height;
    if (indexPath.row == 4) {
        height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:ScreenHeight*4 font:15 :string];
        
    }
    else{
        height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:40 font:15 :string];
    }
    
    CGRect rect = cell.labelTiele.frame;
    rect.origin.x = 10;
    rect.size.width = ScreenWidth-20;
    rect.size.height = height;
    cell.labelTiele.frame = rect;
    //    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark - 删除
-(void)clickDelete
{
    [LSZRequestData initWithDeleteThreeSessionsLesson:self.branchActivitiesMg.id_id :^(BOOL isOk, NSString * string, NSString * str) {
        if (isOk == YES) {
            [self.navigationController  popViewControllerAnimated:YES];
        }else{
            [self initWithtring:string];
        }
    }];
}
-(UITableView *)tableViewDetailsBranchActivities
{
    if(_tableViewDetailsBranchActivities == nil){
        _tableViewDetailsBranchActivities = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth,ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewDetailsBranchActivities.delegate = self;
        _tableViewDetailsBranchActivities.dataSource = self;
        _tableViewDetailsBranchActivities.estimatedRowHeight=0;
    _tableViewDetailsBranchActivities.estimatedSectionFooterHeight =0;
    _tableViewDetailsBranchActivities.estimatedSectionHeaderHeight =0;
        _tableViewDetailsBranchActivities.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableViewDetailsBranchActivities setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewDetailsBranchActivities];
    }
    return _tableViewDetailsBranchActivities;
}
@end
